package paperockscissors;

public class RockPaperScissors {
        
        public RockPaperScissors(){
                
        }
        
        public Result play(Player p1, Player p2) {
                int size = p1.getRPSEnumLength();
        if(p2.getRPSEnumLength() < size)
                size = p2.getRPSEnumLength();
       
        for(int i=0;i<size;i++)
        {
                Result res =  play(p1.getNextMove(), p2.getNextMove());
            switch(res){
                case WIN: p1.setScore(p1.getScore()+1);
                        break;

                case LOST: p2.setScore(p2.getScore()+1);
                        break;
                       
                case TIE: p2.setScore(p2.getScore()+1);
                    p1.setScore(p1.getScore()+1);
                    break;
            }
        }
       
        if(p1.getScore() > p2.getScore())
                return Result.WIN;
       
        if(p1.getScore() < p2.getScore())
            return Result.LOST;
       
        return Result.TIE;
        }
        
        public Result play(RPSEnum p1, RPSEnum p2){
                  Result r = Result.LOST;
                  
                  switch (p1) {
  
                        //ROCK MOVE
                        case ROCK:
                                switch (p2) {
                                        case SCISSORS: //ROCK vs SCISSORS = ROCK WINS
                                                r=Result.WIN;
                                                break;
   
                                        case PAPER: //ROCK vs PAPER = ROCK LOSES
                                                r=Result.LOST;
                                                break;

                                        case ROCK://ROCK vs ROCK = TIE
                                                r=Result.TIE;
                                                break;
   
                                        default:
                                                r=Result.LOST;
                                                break;
                                }
                                break;
   
                        //PAPER MOVE
                        case PAPER:
                                switch (p2) {
                                        case ROCK://PAPER vs ROCK = PAPER WINS
                                                r=Result.WIN;
                                                break;

                                        case SCISSORS://PAPER vs SCISSORS = SCISSORS WINS
                                                r=Result.LOST;
                                                break;
    
                                        case PAPER://PAPER vs PAPER = TIE
                                                r=Result.TIE;
                                                break;
    
                                        default:
                                                r=Result.LOST;
                                                break;
                                }
                                break;
   
                        //SCISSORS MOVE
                        case SCISSORS:
                                switch (p2) {
                                        case ROCK:
                                                r=Result.LOST;
                                                break;

                                        case PAPER:
                                                r=Result.WIN;
                                                break;
   
                                        case SCISSORS:
                                                r=Result.TIE;
                                                break;
   
                                        default:
                                                r=Result.LOST;
                                                break;
                                }
   
                        default:
                                break;
                  }
                  //return of result
                  return r;
        }
}